class CollaboratorController < ApplicationController

  def index
    @collaborators = Collaborator.find(:all, :order => "id")
  end
  
  def form
    unless authenticate_check?('(ADM:ALL||COLL:ALL||(COLL:VIEW))')
      render :update do |page|
        page.replace_html "collaborator_form" , :partial => '/auth/not_permission'
        page.show "collaborator_form"
      end      
    else
      if params[:id]
        @collaborator = Collaborator.find(params[:id])
      else
        @collaborator = Collaborator.new
        @collaborator.manhours = get_parameter("collaborators","default_manhour")
        @collaborator.manweeks = get_parameter("collaborators","default_manweek")
      end
      render :update do |page|
        page.replace_html "collaborator_form" , :partial => 'form'
        page.show "collaborator_form"
      end      
    end
  end
  
  def create
    @collaborator = Collaborator.new
    if request.post?
      @collaborator.attributes = params[:collaborator]
      if @collaborator.save
        redirect_to :action => "list", :displayform => "none"
      end
    end
  end
  
  def alter
    @collaborator = Collaborator.find(params[:collaborator][:id])
    if request.post?
      @collaborator.attributes = params[:collaborator]
      if @collaborator.save
        redirect_to :action => "list", :displayform => "none"
      end
    end
  end
  
  def list
    @collaborators = Collaborator.find(:all)
    render :update do |page|
      page.replace_html "collaborator_list" , :partial => 'list'
      page.show "collaborator_list"
      if params[:displayform] == 'none'
        page.hide "collaborator_form"
      end
    end
  end
  
  def remove
    if params[:id]
      @collaborator = Collaborator.find(params[:id])
      if @collaborator.destroy
        redirect_to :action => "list", :displayform => "none"
      end
    end
  end
  
end
